<script setup>
import { ref } from "vue";
import Toggle from "../components/Transition/Toggle.vue";
import SlideUpBtn from "../components/Transition/slideUpBtn.vue";
const show = ref(false)
</script>

<template>
  <div>
    <!-- 
      <Transition> 是一个内置组件，这意味着它在任意别的组件中都可以被使用，无需注册。它可以将进入和离开动画应用到通过默认插槽传递给它的元素或组件上。以下条件可触发：
      由 v-if 所触发的切换
      由 v-show 所触发的切换
      由特殊元素 <component> 切换的动态组件
      改变特殊的 key 属性
     -->
    <button @click="show = !show">Toggle</button>
    <!-- 仅支持单个元素或组件作为其插槽内容。组件也必须拥有一个根元素 -->
    <Transition>
      <p v-if="show">hello</p>
    </Transition>
    <hr />
    <h3>为过渡效果命名</h3>
    <Transition name="fade">
      <p v-if="show">hello-fade</p>
    </Transition>
    <hr />
    <h3>css的Transition</h3>
    <Transition name="slide-fade">
      <p v-if="show">css的Transition</p>
    </Transition>
    <hr />
    <h3>css的animation</h3>
    <Transition name="bounce">
      <p v-if="show">Hello here is some bouncy text!</p>
    </Transition>
    <hr />
    <h3>可复用过渡效果</h3>
    <Toggle>
      <div v-if="show">Hello</div>
    </Toggle>
    <hr />
    <h3>可复用过渡效果</h3>
    <SlideUpBtn></SlideUpBtn>
    <hr />
    <h3>组件间过渡</h3>
    <p>Transition 配合 component 组件实现</p>
  </div>
</template>

<style scoped>
.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

/* .v-enter-to,
.v-leave-from {
  color: red
} */

.v-enter-from,
.v-leave-to {
  opacity: 0;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
  color: blue;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/*
  进入和离开动画可以使用不同
  持续时间和速度曲线。
*/
.slide-fade-enter-active {
  transition: all 0.3s ease-out;
}

.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateX(20px);
  opacity: 0;
}

.bounce-enter-active {
  animation: bounce-in 0.5s;
}
.bounce-leave-active {
  animation: bounce-in 0.5s reverse;
}
@keyframes bounce-in {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}
</style>